//
//  XQOrderListController.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/20.
//

#import "XQOrderListController.h"
#import "XQOrderListMenu.h"
#import "GKDPageView.h"
#import "XQOrderListPageController.h"

@interface XQOrderListController ()<GKDPageViewDelegate, GKDPageViewDataSource>
@property (nonatomic,strong) XQOrderListMenu *menuView;
@property (nonatomic, strong) GKDPageView *pageView;
@end

@implementation XQOrderListController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeUI];
    [self makeConstraints];
}

- (void)makeUI {
    [self.navigationBar setTitle:@"Order list"];
    [self.navigationBar setHiddenBack:YES];
    self.view.backgroundColor = kCardColor;
    
    [self.view addSubview:self.menuView];
    [self.view addSubview:self.pageView];
}

- (void)makeConstraints {
    [self.menuView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([UIScreen mainScreen].topHeight+20);
        make.left.right.equalTo(@0);
    }];
    [self.pageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.menuView.mas_bottom).offset(20);
        make.left.right.equalTo(@0);
        make.bottom.mas_equalTo(-[UIScreen mainScreen].tabBarHeight - [UIScreen mainScreen].bottomHeight);
    }];
}

#pragma mark - GKDPageViewDelegate, GKDPageViewDataSource

- (void)pageView:(GKDPageView *)pageView didSelectedAtIndex:(NSInteger)index {
    [self.menuView setIndex:index];
}

- (NSInteger)numberOfViewControllersInPageView {
    return 4;
}

- (UIViewController *)viewControllerAtIndex:(NSInteger)index {
    NSArray *arr = @[@"4",@"7",@"6",@"5"];
    XQOrderListPageController *vc = [XQOrderListPageController new];
    [vc setOrient:arr[index]];
    return vc;
}

#pragma mark - lazy

- (XQOrderListMenu *)menuView {
    if (!_menuView) {
        _menuView = [[XQOrderListMenu alloc] init];
        @weakify(self);
        _menuView.buttonHandle = ^(NSInteger index) {
            @strongify(self);
            [self.pageView setActiveIndex:index animated:YES];
        };
    }
    return _menuView;
}

- (GKDPageView *)pageView {
    if (!_pageView) {
        _pageView = [[GKDPageView alloc] initWithContainerViewController:self];
        _pageView.delegate = self;
        _pageView.dataSource = self;
    }
    return _pageView;
}

@end
